﻿/*----------------------------------------------------------------
// PiPiBugNet
// Copyright (C) 2009-2010 
//
// 功能描述：用户逻辑访问类
//
// 创建人:张沛沛
// 创建日期: 2009.08.12
// 
// 修改标识:
// 修改描述:
//
//----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Model;
using SQLServerDAL;

using WebUtility;

namespace BLL
{
    /// <summary>
    /// 用户逻辑访问类
    /// </summary>
    public class UserBLL
    {
        /// <summary>
        /// 添加一个用户
        /// </summary>
        /// <param name="user">用户实体</param>
        /// <returns>是否成功</returns>
        public static bool AddUser(User user)
        {
            bool isAdd = false;
            if (user.UserName.Length > 2)
            {
                UserDAL.AddUser(user);
                isAdd = true;
            }
            else
            {
                isAdd = false;
            }

            return isAdd;
        }

        /// <summary>
        ///  用户登录时检验用户
        /// </summary>
        /// <param name="sName"></param>
        /// <param name="sPass"></param>
        /// <returns></returns>
        public static User CheckUserLogin(string sName, string sPass)
        {
            //密码加密
            string sDES = StrDESEncrypt.StrEncode(sPass, "45852145");

            User us = UserDAL.CheckUserLogin(sName, sDES);
            return us;
        }

        /// <summary>
        /// 根据用户ID获得用户名称
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <returns>用户名</returns>
        public static string GetUserNameByID(int uid)
        {
            return UserDAL.GetUserNameByID(uid);
        }

        /// <summary>
        /// 获取用户角色名称列表
        /// </summary>
        /// <returns></returns>
        public static DataSet GetRoleNameList()
        {
            return UserDAL.GetRoleNameList();
        }

        /// <summary>
        /// 获取用户的密码
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <returns>加密后的密码</returns>
        public static string GetUserPassWord(int uid)
        {
            return UserDAL.GetUserPassWord(uid);
        }

        /// <summary>
        /// 更新用户的密码
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="pwd">加密后的密码</param>
        public static void ChangeUserPassWord(int uid, string pwd)
        {
            UserDAL.ChangeUserPassWord(uid, pwd);
        }
    }
}

